<template>
  <div id="BuildingSampling">
    <div class="banner container-fluid text-center">建筑采风</div>
    <div class="container BuildingSampling-container">
      <!-- 图片展示 -->
      <figure v-for="(image, index) in images" :key="index" class="sample">
        <img :src="image.src" :alt="image.alt" />
        <figcaption>
          <h3>{{ image.caption }}</h3>
        </figcaption>
        <a href="#" @click.prevent="showModal(index)"></a>
      </figure>
    </div>
    
      <!-- 模态框 -->
  <div class="modal" v-if="showModalActive" @click.self="hideModal">
    <span class="close"@click="hideModal">&times;</span>
    <img :src="images[activeImageIndex].src" alt="Large Image Preview" />
    <a href="#" class="prev"@click.prevent="prevImage">&#10094;</a>
    <a href="#" class="next"@click.prevent="nextImage">&#10095;</a>
  </div>

  </div>
</template>

<script setup name="BuildingSampling">
import { ref, onMounted } from 'vue';
//获取模态框元素
const showModalActive = ref(false);
const activeImageIndex = ref(null);
var span = document.getElementsByClassName("close")[0];
var prev = document.getElementsByClassName("prev")[0];
var next = document.getElementsByClassName("next")[0];

const images = [
  {
    src: './src/assets/img//南-1.jpg',
    alt: '胜利仓库-南-1',
    caption: '胜利仓库-南-1'
  },
  {
    src: './src/assets/img//北-1.jpg',
    alt: '胜利仓库-北-1',
    caption: '胜利仓库-北-1'
  },
  {
    src: './src/assets/img//东-1.jpg',
    alt: '胜利仓库-东-1',
    caption: '胜利仓库-东-1'
  },
  {
    src: './src/assets/img//西-1.jpg',
    alt: '胜利仓库-西-1',
    caption: '胜利仓库-西-1'
  }
];

//打开与关闭模态框
const showModal = (index) => {
  activeImageIndex.value = index;
  showModalActive.value = true;
};
const hideModal = () => {
  showModalActive.value = false;
};
//翻页
const prevImage = () => {
  if (activeImageIndex.value === 0) {
    alert('已经是第一张图片了！');
  } else {
    activeImageIndex.value = (activeImageIndex.value - 1) % images.length;
  }
};
const nextImage = () => {
  if (activeImageIndex.value === images.length - 1) {
    alert('已经是最后一张图片了！');
  } else {
    activeImageIndex.value = (activeImageIndex.value + 1) % images.length;
  }
};


</script>

<style scoped>
.banner {
  color: #fff;
  font-size: 30px;
  height: 150px;
  line-height: 150px;
  background-image: url('../assets/img/banner1.png');
  background-repeat: no-repeat;
  background-size: cover;
  background-attachment: scroll;
  background-position: center center;
}
.BuildingSampling-container {
  padding: 80px 80px;
  transition: all ease 0.5s;
}
@import url(https://fonts.googleapis.com/css?family=Open+Sans:600;);

.sample {
  background-color: #000;
  display: inline-block;
  font-family: 'Open Sans', sans-serif;
  font-size: 16px;
  margin: 10px;
  max-width: 315px;
  min-width: 230px;
  overflow: hidden;
  position: relative;
  text-align: center;
  width: 100%;
}
.sample * {
  -webkit-box-sizing: border-box;
          box-sizing: border-box;
  -webkit-transition: all 0.35s ease;
          transition: all 0.35s ease;
}
.sample:before,
.sample:after {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  -webkit-transition: all 0.35s ease;
          transition: all 0.35s ease;
  background-color: #000;
  border-left: 3px solid #fff;
  border-right: 3px solid #fff;
  content: '';
  opacity: 0.9;
  z-index: 1;
}
.sample:before {
  -webkit-transform: skew(45deg) translateX(-155%);
          transform: skew(45deg) translateX(-155%);
}
.sample:after {
  -webkit-transform: skew(45deg) translateX(155%);
          transform: skew(45deg) translateX(155%);
}
.sample img {
  backface-visibility: hidden;
  max-width: 100%;
  vertical-align: top;
}
.sample figcaption {
  top: 50%;
  left: 50%;
  position: absolute;
  z-index: 2;
  -webkit-transform: translate(-50%, -50%) scale(0.5);
          transform: translate(-50%, -50%) scale(0.5);
  opacity: 0;
  -webkit-box-shadow: 0 0 10px #000;
          box-shadow: 0 0 10px #000;
}
.sample h3 {
  background-color: #000;
  border: 2px solid #fff;
  color: #fff;
  font-size: 1em;
  font-weight: 600;
  letter-spacing: 1px;
  margin: 0;
  padding: 5px 10px;
  text-transform: uppercase;
}
.sample a {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 3;
}
.sample:hover > img {
  opacity: 0.5;
}
.sample:hover:before {
  -webkit-transform: skew(45deg) translateX(-55%);
          transform: skew(45deg) translateX(-55%);
}
.sample:hover:after {
  -webkit-transform: skew(45deg) translateX(55%);
          transform: skew(45deg) translateX(55%);
}
.sample:hover figcaption {
  -webkit-transform: translate(-50%, -50%) scale(1);
          transform: translate(-50%, -50%) scale(1);
  opacity: 1;
}
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999999999;
}

.modal img {
  max-width: 90%;
  max-height: 90%;
}

.close {
  position: absolute;
  top: 15px;
  right: 35px;
  color: #f1f1f1;
  font-size: 40px;
  font-weight: bold;
  transition: 0.3s;
}

.close:hover,
.close:focus {
  color: #e11d1d;
  text-decoration: none;
  cursor: pointer;
}

.prev, .next {
  cursor: pointer;
  position: absolute;
  top: 50%;
  width: auto;
  padding: 50px;
  margin-top: -100px;
  color: white;
  font-weight: bold;
  font-size: 100px;
  transition: 0.3s;
  border-radius: 0 3px 3px 0;
  user-select: none;
}

.prev {
  left: 0;
  border-radius: 3px 0 0 3px;
}

.next {
  right: 0;
  border-radius: 0 3px 3px 0;
}

.prev:hover,
.prev:focus,
.next:hover,
.next:focus {
  color: #b69783;
  text-decoration: none;
  cursor: pointer;
}



</style>

